package com.chanyachting.emall.action.hr;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Applicationleter;
import com.chanyachting.emall.form.JobSearchForm;
import com.chanyachting.emall.service.ApplicationLeterService;
import com.chanyachting.emall.serviceImpl.ApplicationLeterServiceImpl;
import com.chanyachting.emall.util.PageUtil;

public class QueryAppJob extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//一般页面记录数
		int COMMON_PAGE_SIZE = 20;
		
		ApplicationLeterService alService = new ApplicationLeterServiceImpl();
		List<Applicationleter> alList = null;
		JobSearchForm tForm = (JobSearchForm)form;
		String keyword = tForm.getKeyword();
		int currentPage = tForm.getCurrentPage();
		int pageSize = COMMON_PAGE_SIZE;
		
		int pageCount = alService.getApplicationleterCount("01")/pageSize;
		
		if (pageCount%pageSize > 0) {
			pageCount = pageCount + 1;
		}
		
		if (currentPage < 1) {
			currentPage = 1;
		} else if (currentPage > pageCount) {
			return mapping.findForward("error");
		}
		
//		if(null != keyword && !"".equals(keyword)){
//			keyword = keyword.replace(' ', '%');
//			keyword = "%" + keyword + "%";
//			alList = alService.getApplicationleterByKeyword(keyword);
//		}else{
		    alList = alService.getAllApplicationleterByPageBreak(currentPage - 1, pageSize);
//		}

		tForm.setJobList(alList);
		String toPageAct = PageUtil.getGotoAction(request.getRequestURL().toString(), request.getParameterMap());
		String linkStr = PageUtil.getFy3(pageCount, currentPage, toPageAct);
		tForm.setLinkStr(linkStr);
		return mapping.findForward("appJobs");
	}
}
